package cn.maxhou.service.impl;

import cn.maxhou.entity.SysUser;
import cn.maxhou.mapper.SysUserMapper;
import cn.maxhou.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("sysUserService2")
public class SysUserServiceImpl3 implements SysUserService {

    @Autowired
    private SysUserMapper sysUserMapper;
    @Override
    public List<SysUser> findgList(SysUser sysUser) {
        return sysUserMapper.getSysUserList(sysUser);
    }

    @Override
    public int saveBatch(List<SysUser> sysUserList) {
        int rows=0;
        for (int i = 0; i < sysUserList.size(); i++) {
            //拿出每一条用户数据插入
            SysUser sysUser = sysUserList.get(i);
            if (i==1){
                //插入第二条数据时,模拟数据库异常,查看业务是否生效
                throw  new RuntimeException("数据库异常");
            }
            //调用插入数据操作,记入总影响行数
            rows+=sysUserMapper.insert(sysUser);
        }
        //返回总受影响行数
        return rows;
    }

    //提供setter方法用于注入属性
    public void setSysUserMapper(SysUserMapper sysUserMapper) {
        this.sysUserMapper = sysUserMapper;
    }
}
